//
//  HXBluetoothSearchListCell.m
//  HongxuanBluetooth
//
//  Created by 广州弘轩科技发展有限公司 on 2023/8/7.
//

#import "HXBluetoothSearchListCell.h"

@implementation HXBluetoothSearchListCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle  = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self initSubView];
    }
    return self;
}

- (void)initSubView{
    if([themeColors isEqualToString:@"default"]){
        self.contentView.backgroundColor = [UIColor blackColor];
        
    }else{
        self.contentView.backgroundColor = midnightRGB;
    }
    self.contentView.userInteractionEnabled = YES;
    UIButton *selebt = [[UIButton alloc] init];
    self.selebt = selebt;
    [selebt setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [selebt setImage:[UIImage imageNamed:@"deviceselecticon"] forState:UIControlStateSelected];
    [self.contentView addSubview:selebt];
    [selebt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
//        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(13);
//        make.width.mas_equalTo(258);
        make.width.mas_equalTo(25);
    }];
    [selebt addTarget:self action:@selector(didclcikSelect:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *equipmentlogo = [[UIImageView alloc] init];
    equipmentlogo.image = [UIImage imageNamed:@"watchlogo"];
    [self.contentView addSubview:equipmentlogo];
    [equipmentlogo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(56);
        make.top.mas_equalTo(15);
        make.width.height.mas_equalTo(20);
    }];
    
    UILabel *idname= [[UILabel alloc] init];
//    idname.text = self.idnamestr;
    idname.textColor = [UIColor whiteColor];
    idname.textAlignment = NSTextAlignmentLeft;
    self.inname = idname;
    [self.contentView addSubview:idname];
    [idname mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(equipmentlogo.mas_right).offset(8);
        make.top.mas_equalTo(15);
        make.height.mas_equalTo(20);
        
    }];
    UIImageView *line = [[UIImageView alloc] init];
    line.image = [UIImage imageNamed:@"shebeiline"];
    [self.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
//    selectcell
//    self.selectview = [[UIImageView alloc] init];
//    self.selectview.image = [UIImage imageNamed:@"selectcell"];
//    [self.contentView addSubview:self.selectview];
//    [self.selectview mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(13.67);
//        make.left.mas_equalTo(15.33);
//        make.width.mas_equalTo(20.33);
//        make.height.mas_equalTo(23.33);
//    }];
    
}
-(void)setModel:(HXBluetoothConnectionDataModel *)model{
    _model = model;
    self.inname.text = model.kCBAdvDataLocalName;
    if(model.kCBAdvDataLocalName == nil){
        self.inname.text = self.kCBAdvDataLocalName;
    }
    if([model.kCBAdvDataislink isEqualToString:@"1"]){
        self.inname.textColor = [UIColor greenColor];
        
    }else{
        self.inname.textColor = [UIColor whiteColor];
    }
    NSLog(@"model.kCBAdvDataislink :%@",model.kCBAdvDataislink);
}
//-(void)setIdnamestr:(NSString *)idnamestr{
//    _idnamestr = idnamestr;
//    _inname.text = idnamestr;
//}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state

}


-(void)didclcikSelect:(UIButton *)button{
    __weak typeof(self) weakSelf = self;
    if(self.didseleBlock){
        weakSelf.didseleBlock(_didselectindex);
    }
    
}

@end
